﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Axis.Dao.Core;
using Axis.BusinessObject.Response;
using Axis.BusinessObject.Core;
using Axis.Web.Administrator.Global;

namespace Axis.Web.Administrator.Views.Accounts
{
    public partial class User : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CSecurity.IS_SUPER_ADMIN && !CSecurity.IS_HOST_ADMIN)
            {
              //  Response.Redirect("~/Administrator");
            }
            if (!IsPostBack)
            {
                IList<CListData> allCloundTabs = new CCoreDao().GetListData(string.Format("<InputValue UserID='{0}' SecrectToken='{1}'  FunctionCode='MenuCategory' Context='GroupUser' />", CSecurity.USER_ID, CSecurity.SECRECT_TOKEN));
                ddlCategory.DataSource = allCloundTabs;
                ddlCategory.DataTextField = "Name";
                ddlCategory.DataValueField = "ID";
                ddlCategory.DataBind();
                ddlCategory.Items.Insert(0, new ListItem("(Tất cả)", "0"));

            }
            
        }
        protected void GetListData(string functionCode, object[] arrDDL)
        {
            if (arrDDL != null && arrDDL.Length > 0)
            {
                IList<CListData> list = new CCore().GetListData(functionCode);
                string defaultValue = "";
                foreach (CListData data in list)
                {
                    if (data.IsDefault)
                    {
                        defaultValue = data.Value;
                    }
                }
                foreach (object obj in arrDDL)
                {
                    DropDownList ddl = (DropDownList)obj;
                    ddl.DataSource = list;
                    ddl.DataTextField = "Name";
                    ddl.DataValueField = "Value";
                    ddl.DataBind();
                    if (ddl.Attributes["multiple"] == "multiple")
                    {
                        ddl.Items.Insert(0, new ListItem("(all)", ""));
                    }
                    else
                    {
                        /* Set Default Value */
                        ddl.SelectedValue = defaultValue;
                        ddl.SelectedItem.Attributes["Default-Value"] = "1";
                    }
                }
            }
        }
    }
}